package com.zhuiyun.project.api.caseRecord.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.caseRecord.entity.CaseRecord;
import com.zhuiyun.project.api.caseRecord.mapper.CaseRecordMapper;
import com.zhuiyun.project.api.caseRecord.service.CaseRecordService;
import com.zhuiyun.project.api.coachmanagement.entity.CoachManagement;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分账管理模块
 * @ClassName CaseController
 * @Description TODO 案例管理
 * @Author lpr
 * @Date 2023/9/1 08:40
 **/
@RestController
@RequestMapping("caseRecord")
@Api(tags = "案例管理")
@Slf4j
public class CaseRecordController extends BaseController {
    @Resource
    CaseRecordService caseRecordService;

    @Resource
    CaseRecordMapper caseRecordMapper;

    /**
     * 分页查询+模糊查询 案例管理
     * @Author lpr
     * @Description
     * @Date 2023/11/02 19:29
     * @Return com.zhuiyun.project.common.response.CommonResult
     * @param pageRequest
     * @param caseRecord
     */
    @PreAuthorize("@ss.hasPermi('caseRecord:case:list')")
    @ApiOperation(value = "案例管理查询")
    @OptLog(modular = "案例管理", type = CommonConstants.SELECT, describe = "案例管理查询 ")
    @GetMapping("/listCaseRecord")
    public CommonResult list(PageRequest pageRequest, CaseRecord caseRecord) {
        IPage<CaseRecord> list = caseRecordService.selectCaseRecord(pageRequest, caseRecord);
        return CommonResult.ok(list);
    }
    /**
     * @Author lpr
     * @Description 状态修改
     * @Date 2023/11/03 13:40
     * @param caseRecord
     */
    @PreAuthorize("@ss.hasPermi('caseRecord:editCaseStatus')")
    @ApiOperation(value = "修改案例状态")
    @OptLog(modular = "案例管理", type = CommonConstants.UPDATE , describe = "修改案例状态")
    @PutMapping("/editCaseStatus")
    public CommonResult editCaseStatus(@RequestBody CaseRecord caseRecord){
        return CommonResult.ok(caseRecordService.editCaseStatus(caseRecord));
    }
    /**
     * @Author lpr
     * @Description 案例删除
     * @Date 2023/11/03 13:40
     * @param caseId
     */
    @PreAuthorize("@ss.hasPermi('caseRecord:editCaseStatus')")
    @ApiOperation(value = "案例删除")
    @OptLog(modular = "案例管理", type = CommonConstants.UPDATE , describe = "案例删除")
    @DeleteMapping("/removeCaseById/{caseId}")
    public CommonResult removeCaseById(@PathVariable Integer caseId){
        return caseRecordService.removeCaseById(caseId);
    }

    /*
    * @Author xy
    * @Description todo 案例查询
    * @Date 2023/11/24 9:31
    * @Return
    * @param
    */
    @ApiOperation(value = "学员案例查询")
    @OptLog(modular = "案例管理", type = CommonConstants.SELECT, describe = "学员案例查询 ")
    @GetMapping("/listCase")
    public CommonResult listCase(@RequestParam Integer coachId,@RequestParam Integer userId) {
        // 根据前端传过来的coachId（教练id）来查询案例表id符合的数据
        QueryWrapper<CaseRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("coach_id",coachId);
        queryWrapper.eq("member_id",userId);
        List<CaseRecord> caseRecords = caseRecordMapper.selectList(queryWrapper);
        return CommonResult.ok(caseRecords);
    }
}
